/**
* 左边菜单
router :default-active="$route.path"
*/
<template>
  <el-menu default-active="2" :collapse="collapsed" collapse-transition unique-opened class="el-menu-vertical-demo"
    router background-color="#334157" text-color="#fff" active-text-color="#ffd04b">
    <div class="logobox">
      <img class="logoimg" src="../assets/img/logo.png" alt="">
    </div>

    <!-- 一级别菜单 -->
    <!-- <el-menu-item v-for="item in menus" :index="'/' + item.url" :key="item.menuid">
      <i class="iconfont" :class="item.icon"></i>
      <span slot="title">{{ item.menuname }}</span>
    </el-menu-item> -->

    <!-- 二级子菜单 -->
    <el-submenu v-for="menu in allmenu" :key="menu.menuid" :index="menu.menuname">
      <template slot="title">
        <i :class="menu.icon"></i>
        <span>{{ menu.menuname }}</span>
      </template>
      <el-menu-item-group>
        <el-menu-item v-for="chmenu in menu.menus" :index="'/' + chmenu.url" :key="chmenu.menuid">
          <i :class="chmenu.icon"></i>
          <span>{{ chmenu.menuname }}</span>
        </el-menu-item>
      </el-menu-item-group>
    </el-submenu>


  </el-menu>
</template>
<script>
import { menu } from '../api/userMG'
export default {
  name: 'leftnav',
  data() {
    return {
      collapsed: false,
      allmenu: []
    }
  },
  // 创建完毕状态(里面是操作)
  created() {
    let res = {
      success: true,
      data: [
        {
          menuid: 1,
          icon: 'el-icon-s-platform',
          menuname: '电商管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 1001,
              icon: 'el-icon-user-solid',
              menuname: '代理管理',
              hasThird: 'N',
              url: 'commerce/StoreManager',
              menus: null
            },
            {
              menuid: 1002,
              icon: 'el-icon-s-goods',
              menuname: '商品管理',
              hasThird: 'N',
              url: 'commerce/Goods',
              menus: null
            },
            {
              menuid: 1003,
              icon: 'el-icon-document',
              menuname: '评价信息',
              hasThird: 'N',
              url: 'commerce/Evaluation',
              menus: null
            }
            , {
              menuid: 1004,
              icon: 'el-icon-female',
              menuname: '客户管理',
              hasThird: 'N',
              url: 'commerce/CustomerManagement',
              menus: null
            }
          ]
        }, {
          menuid: 3,
          icon: 'el-icon-s-order',
          menuname: '订单管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 4,
              icon: 'el-icon-s-marketing',
              menuname: '交易订单',
              hasThird: 'N',
              url: 'order/Order',
              menus: null
            }
          ]
        }, {
          menuid: 12,
          icon: 'el-icon-s-management',
          menuname: '支付管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 13,
              icon: 'el-icon-s-operation',
              menuname: '支付配置',
              hasThird: 'N',
              url: 'pay/Config',
              menus: null
            }

          ]
        }, {
          menuid: 15,
          icon: 'el-icon-s-data',
          menuname: '图表',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 16,
              icon: 'el-icon-set-up',
              menuname: '数据可视化',
              hasThird: 'N',
              url: 'charts/statistics',
              menus: null
            }
          ]
        }, {
          menuid: 5,
          icon: 'el-icon-s-platform',
          menuname: '系统管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 6,
              icon: 'el-icon-s-custom',
              menuname: '用户管理',
              hasThird: 'N',
              url: 'system/User',
              menus: null
            },

            {
              menuid: 8,
              icon: 'el-icon-user',
              menuname: '角色管理',
              hasThird: 'N',
              url: 'system/Role',
              menus: null
            },
            {
              menuid: 7,
              icon: 'el-icon-s-grid',
              menuname: '菜单管理',
              hasThird: 'N',
              url: 'system/Module',
              menus: null
            },
            {
              menuid: 11,
              icon: 'el-icon-lock',
              menuname: '权限管理',
              hasThird: 'N',
              url: 'system/Permission',
              menus: null
            }
          ]
        }

      ],

      msg: 'success'
    }
    this.allmenu = res.data
    // this.menus = res.menus

    // menu(localStorage.getItem('logintoken'))
    //   .then(res => {
    //     console.log(JSON.stringify(res))
    //     if (res.success) {
    //       this.allmenu = res.data
    //     } else {
    //       this.$message.error(res.msg)
    //       return false
    //     }
    //   })
    //   .catch(err => {
    //     this.$message.error('菜单加载失败，请稍后再试！')
    //   })
    // 监听
    this.$root.Bus.$on('toggle', value => {
      this.collapsed = !value
    })
  }
}
</script>
<style>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 240px;
  min-height: 400px;
}

.el-menu-vertical-demo:not(.el-menu--collapse) {
  border: none;
  text-align: left;
}

.el-menu-item-group__title {
  padding: 0px;
}

.el-menu-bg {
  background-color: #1f2d3d !important;
}

.el-menu {
  border: none;
}

.logobox {
  height: 40px;
  line-height: 40px;
  color: #9d9d9d;
  font-size: 20px;
  text-align: center;
  padding: 20px 0px;
}

.logoimg {
  height: 40px;
}
</style>
